package com.heima.wemedia.controller.v1;
/*
    
 需求描述：
 @Author: wang
 @Date: 2022/10/13 22:06
 
 */

import com.heima.common.constants.WeMediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;


    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile) throws IOException {
        return wmMaterialService.upload(multipartFile);
    }

    @PostMapping("/list")
    //{page: 1, size: 20, isCollection: "0"}
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }


    @GetMapping("/del_picture/{id}")
    public ResponseResult delPictureById(@PathVariable("id") Integer id) {

        return wmMaterialService.delPictureById(id);
    }


    /**
     * 取消收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id) {
        return wmMaterialService.cancelCollectOrCollect(id, WeMediaConstants.CANCEL_COLLECT_MATERIAL);
    }

    /**
     * 收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id) {

        return wmMaterialService.cancelCollectOrCollect(id, WeMediaConstants.COLLECT_MATERIAL);
    }


}
